from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 正向用例1 ： case_002  输入有效小区名称搜索并筛选，搜索成功

driver = webdriver.Firefox()
driver.maximize_window()
driver.get('https://beijing.anjuke.com/')
# 强制等待
sleep(2)
# 隐式等待
driver.implicitly_wait(10)
# 点击登录
driver.find_element(By.CSS_SELECTOR, '.user-login').click()
sleep(30)

# 1、输入小区名称   显示等待
xq = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.ID, 'search-input'))
)
xq.send_keys('昌平')
sleep(3)
# 2、点击二手车
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[1]/div[1]/div[6]/div[3]/div/div[2]/div[1]/section/form/div/button[1]').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
# 3、选择区域
driver.find_element(By.XPATH, '//a[@href="https://beijing.anjuke.com/sale/changping/?kw=昌平&q=昌平"]').click()
sleep(2)
# 4、选择售价
driver.find_element(By.XPATH, '/html/body/div[1]/div/div/section/section[2]/div/section/div[2]/section/ul/li[2]/a').click()
sleep(2)
# 5、选择房型
driver.find_element(By.XPATH, '//*[@id="esfMain"]/section/section[2]/div/section/div[4]/section/ul/li[2]/a').click()
sleep(2)
# 6、选择特色
driver.find_element(By.CSS_SELECTOR, '#esfMain > section > section.filter-wrap > div > section > div:nth-child(5) > section > ul > li:nth-child(1) > label > i').click()
sleep(2)
# 7、点击筛选的第一张图片
tp = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/section/section[3]/section[1]/div/div/div/div/div/img')
# 获取元素文本
print(f"元素文本：{tp.text}")
# 获取元素尺寸
print(f"元素尺寸-宽度：{tp.size['width']}, 高度：{tp.size['height']}")
# 获取元素坐标
print(f"元素坐标-x：{tp.location['x']}, y:{tp.location['y']}")
tp.click()

sleep(10)






